package com.lhj.xxsc.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 罗惠江
 * @version 1.0
 * @email 1511619294@qq.com
 * @date 2020/11/23 14:42
 */

/**
 * 1.导入依赖
 *
 * 2.编写配置 , 给容器注入一个 RestHighLevelClient
 * 3.操作 参考 官方的api 文档
 */
@Configuration
public class XxscElasticSearchConfig {
	public static final RequestOptions COMMON_OPTIONS;
	static {
		RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
		COMMON_OPTIONS = builder.build();
	}
	@Bean
	public RestHighLevelClient esRestClient() {
		RestClientBuilder builder = null;

		builder = RestClient.builder(new HttpHost("8.129.113.72", 9200, "http"));

		RestHighLevelClient client = new RestHighLevelClient(builder);


//    RestHighLevelClient client = new RestHighLevelClient(
//          RestClient.builder(
//                new HttpHost("8.129.113.72", 9200, "http")
//                // 如果多个，就这样可以了
//                 // ,new HttpHost("8.129.113.72", 9200, "http")
//          ));
		return client;

	}
}
